//
//  ZCRouteViewController.m
//  03地图定位
//
//  Created by 张聪 on 16/7/26.
//  Copyright © 2016年 张聪. All rights reserved.
//

#import "ZCRouteViewController.h"
#import "Masonry.h"

@interface ZCRouteViewController ()

@property (nonatomic, strong) UILabel *startLab;
@property (nonatomic, strong) UILabel *endLab;
@property (nonatomic, strong) UITextField *startAddess;
@property (nonatomic, strong) UITextField *endAddess;
@property (nonatomic, strong) UITextField *startTextField;
@property (nonatomic, strong) UITextField *endTextField;

@end

@implementation ZCRouteViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor grayColor];
    
    
    [self settingUI];
    
    
    
}

- (void)settingUI {
    
    UILabel *startLab = [[UILabel alloc] init];
    self.startLab = startLab;
    startLab.font = [UIFont systemFontOfSize:13];
    startLab.text = @"起点:";
    [self.view addSubview:startLab];
    
    [startLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(40);
        make.leading.equalTo(self.view).offset(20);
        make.width.mas_equalTo(35);
        make.height.mas_equalTo(30);
    }];
    
    UILabel *endLab = [[UILabel alloc] init];
    self.endLab = endLab;
    endLab.font = [UIFont systemFontOfSize:13];
    endLab.text = @"终点:";
    [self.view addSubview:endLab];
    
    [endLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(startLab).offset(40);
        make.leading.equalTo(self.view).offset(20);
        make.width.mas_equalTo(35);
        make.height.mas_equalTo(30);
    }];
    
    UITextField *startAddess = [[UITextField alloc] init];
    self.startAddess = startAddess;
    startAddess.font = [UIFont systemFontOfSize:13];
    startAddess.placeholder = @"东方明珠电视塔";
    startAddess.borderStyle = UITextBorderStyleRoundedRect;
    [self.view addSubview:startAddess];
    
    [startAddess mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(startLab);
        make.trailing.equalTo(self.view).offset(-20);
        make.width.mas_equalTo(150);
        make.height.mas_equalTo(30);
    }];
    
    
    UITextField *endAddess = [[UITextField alloc] init];
    self.endAddess = endAddess;
    endAddess.font = [UIFont systemFontOfSize:13];
    endAddess.placeholder = @"黄鹤楼";
    endAddess.borderStyle = UITextBorderStyleRoundedRect;
    [self.view addSubview:endAddess];
    
    [endAddess mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(endLab);
        make.trailing.equalTo(self.view).offset(-20);
        make.width.mas_equalTo(150);
        make.height.mas_equalTo(30);
    }];
    
    
    UITextField *startTextField = [[UITextField alloc] init];
    self.startTextField = startTextField;
    [startTextField becomeFirstResponder];
    startTextField.borderStyle = UITextBorderStyleRoundedRect;
    startTextField.font = [UIFont systemFontOfSize:13];
    startTextField.placeholder = @"上海";
    [self.view addSubview:startTextField];
    
    [startTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(startLab);
        make.leading.equalTo(startLab.mas_trailing).offset(20);
        make.trailing.equalTo(startAddess.mas_leading).offset(-20);
        make.height.mas_equalTo(30);
    }];
    
    UITextField *endTextField = [[UITextField alloc] init];
    self.endTextField = endTextField;
    endTextField.borderStyle = UITextBorderStyleRoundedRect;
    endTextField.font = [UIFont systemFontOfSize:13];
    endTextField.placeholder = @"武汉";
    [self.view addSubview:endTextField];
    
    [endTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(endLab);
        make.leading.equalTo(endLab.mas_trailing).offset(20);
        make.trailing.equalTo(endAddess.mas_leading).offset(-20);
        make.height.mas_equalTo(30);
    }];
    

    UIButton *busBtn = [[UIButton alloc] init];
    busBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [busBtn setTitle:@"公交" forState:UIControlStateNormal];
    busBtn.backgroundColor = [UIColor orangeColor];
    [busBtn addTarget:self action:@selector(didBusClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:busBtn];
    
    
    
    UIButton *carBtn = [[UIButton alloc] init];
    carBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    carBtn.backgroundColor = [UIColor orangeColor];
    [carBtn setTitle:@"驾乘" forState:UIControlStateNormal];
    
    [carBtn addTarget:self action:@selector(didCarClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:carBtn];
    
    UIButton *walkBtn = [[UIButton alloc] init];
    walkBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    walkBtn.backgroundColor = [UIColor orangeColor];
    [walkBtn setTitle:@"步行" forState:UIControlStateNormal];
    
    [walkBtn addTarget:self action:@selector(didWalkClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:walkBtn];
    
    
    [busBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(endAddess.mas_bottom).offset(40);
        make.leading.equalTo(self.view).offset(20);
        make.width.equalTo(carBtn);
        make.height.mas_equalTo(30);
    }];
    
    [carBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(endAddess.mas_bottom).offset(40);
        make.trailing.equalTo(walkBtn.mas_leading).offset(-20);
        make.leading.equalTo(busBtn.mas_trailing).offset(20);
        make.width.equalTo(walkBtn);
        make.height.mas_equalTo(30);
    }];
    
    [walkBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(endAddess.mas_bottom).offset(40);
        make.trailing.equalTo(self.view).offset(-20);
        make.width.equalTo(busBtn);
        make.height.mas_equalTo(30);
    }];
    
   
}

#pragma mark - 事件响应
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self dismissViewControllerAnimated:YES completion:nil];
    [self.view endEditing:YES];
}

//公交
- (void)didBusClick {
    if ([self.RouteViewControllerDelegate respondsToSelector:@selector(didBusClick:endAddess:stratSerchCity:endSerchCity:)]) {
        [self.RouteViewControllerDelegate didBusClick:self.startAddess.text endAddess:self.endAddess.text stratSerchCity:self.startTextField.text endSerchCity:self.endTextField.text];
    }
    [self dismissViewControllerAnimated:YES completion:nil];
    
}

//驾乘
- (void)didCarClick {
    if ([self.RouteViewControllerDelegate respondsToSelector:@selector(didCarClick:endAddess:stratSerchCity:endSerchCity:)]) {
        [self.RouteViewControllerDelegate didCarClick:self.startAddess.text endAddess:self.endAddess.text stratSerchCity:self.startTextField.text endSerchCity:self.endTextField.text];
    }
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}

//步行
- (void)didWalkClick {
    if ([self.RouteViewControllerDelegate respondsToSelector:@selector(didWalkClick:endAddess:stratSerchCity:endSerchCity:)]) {
        [self.RouteViewControllerDelegate didWalkClick:self.startAddess.text endAddess:self.endAddess.text stratSerchCity:self.startTextField.text endSerchCity:self.endTextField.text];
    }
    
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
